﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： GcGroupUserRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/10/28
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	///群成员信息 仓储层
	/// </summary>	
	public class GcGroupUserRepository:BaseRepository<GcGroupUser>
	{		
    
        #region 构造

        public GcGroupUserRepository() : base(){}

        public GcGroupUserRepository(string connectionString) : base(connectionString){}

        public GcGroupUserRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public List<GcGroupUser> GetListByGroupId(int groupId)
        {
            StringBuilder sb = new StringBuilder("SELECT * FROM GcGroupUser T WITH(NOLOCK) ");
            sb.Append(" WHERE GroupID=@GroupID");
            return Query(sb.ToString(), new { GroupID = groupId });
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public GcGroupUser GetInfoByGroupIdWxId(int groupId,string wxid)
        {
            StringBuilder sb = new StringBuilder("SELECT * FROM GcGroupUser T WITH(NOLOCK) ");
            sb.Append(" WHERE GroupID=@GroupID and wxid=@wxid");
            return FirstOrDefault(sb.ToString(), new { GroupID = groupId,wxid=wxid });
        }

        /// <summary>
        /// 设置退群用户
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public void SetQuitUserByIds(List<int> ids)
        {
            if (ids.Count==0)
            {
                return;
            }
            string userIds = string.Join(",", ids.ToArray());
            StringBuilder sb = new StringBuilder("UPDATE GcGroupUser SET QuitGroupTime=GETDATE(),UpdatedTime=GETDATE() ");
            sb.Append(" WHERE GroupUserID in("+ userIds + ")");
            Execute(sb.ToString());
        }
    }
}